package com.bigdata.service.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bigdata.common.annotation.RepeatSubmit;
import com.bigdata.common.annotation.Log;
import com.bigdata.common.core.controller.BaseController;
import com.bigdata.common.core.domain.PageQuery;
import com.bigdata.common.core.domain.R;
import com.bigdata.common.core.validate.AddGroup;
import com.bigdata.common.core.validate.EditGroup;
import com.bigdata.common.core.validate.QueryGroup;
import com.bigdata.common.enums.BusinessType;
import com.bigdata.common.utils.poi.ExcelUtil;
import com.bigdata.service.domain.vo.TagsVo;
import com.bigdata.service.domain.bo.TagsBo;
import com.bigdata.service.service.ITagsService;
import com.bigdata.common.core.page.TableDataInfo;

/**
 * 标签字典
 *
 * @author ruoyi
 * @date 2025-07-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/service/tags")
public class TagsController extends BaseController {

    private final ITagsService iTagsService;

    /**
     * 查询标签字典列表
     */
    @SaCheckPermission("service:tags:list")
    @GetMapping("/list")
    public TableDataInfo<TagsVo> list(TagsBo bo, PageQuery pageQuery) {
        return iTagsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出标签字典列表
     */
    @SaCheckPermission("service:tags:export")
    @Log(title = "标签字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TagsBo bo, HttpServletResponse response) {
        List<TagsVo> list = iTagsService.queryList(bo);
        ExcelUtil.exportExcel(list, "标签字典", TagsVo.class, response);
    }

    /**
     * 获取标签字典详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("service:tags:query")
    @GetMapping("/{id}")
    public R<TagsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iTagsService.queryById(id));
    }

    /**
     * 新增标签字典
     */
    @SaCheckPermission("service:tags:add")
    @Log(title = "标签字典", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TagsBo bo) {
        return toAjax(iTagsService.insertByBo(bo));
    }

    /**
     * 修改标签字典
     */
    @SaCheckPermission("service:tags:edit")
    @Log(title = "标签字典", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TagsBo bo) {
        return toAjax(iTagsService.updateByBo(bo));
    }

    /**
     * 删除标签字典
     *
     * @param ids 主键串
     */
    @SaCheckPermission("service:tags:remove")
    @Log(title = "标签字典", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iTagsService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
